package etc

import (
	"errors"
	"flag"
	"github.com/spf13/viper"
)

var (
	configName = flag.String("etc", "application-dev", "配置文件")
)

func SetupYmlConfig() (configure *Configuration, err error) {
	viperIns := viper.New()
	viperIns.AddConfigPath("./etc")
	viperIns.SetConfigType("yml")
	viperIns.SetConfigName(*configName)

	if err := viperIns.ReadInConfig(); err != nil {
		return nil, err
	}
	if err := viperIns.Unmarshal(&configure); err != nil {
		return nil, err
	}

	if configure == nil {
		return nil, errors.New("configure parsing fail")
	}
	return configure, nil
}
